import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios';
import VueAxios from 'vue-axios';
import VueCookies from 'vue-cookies';

Vue.use(VueCookies);
Vue.use(VueAxios, axios);
Vue.use(ElementUI);
Vue.config.productionTip = false

//请求拦截器
axios.interceptors.request.use(
  config => {
    config.baseURL = "http://localhost:5255/api/";
    config.headers.Authorization = "Bearer " + VueCookies.get("token");
    return config;
  }
)
//响应拦截器
axios.interceptors.response.use(
  res => {
    return res;
  },
  error => {
    if (error.response && error.response.status == 401) {
      alert("没有授权,请先登录");
      router.push("/");
    }
    return error;
  }
)




new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
